package theOrbalEra.common.player;

import java.util.HashMap;
import java.util.Map;

import net.minecraft.entity.player.EntityPlayer;


public class PlayerHandler {
	public static final Map<String, PlayerHandler> ALL_PLAYERS = new HashMap<String, PlayerHandler>();
	
	public EntityPlayer player;
	public PlayerStatistics stats;
	
	public PlayerHandler(EntityPlayer player, PlayerStatistics stats) {
		this.player = player;
		this.stats = stats;
	}
	
	public static void addPlayer(String username, PlayerHandler player) {
		if(!ALL_PLAYERS.containsKey(username)) {
			ALL_PLAYERS.put(username, player);
		}
	}
	
	public static PlayerHandler getPlayer(String username) {
		return ALL_PLAYERS.get(username);
	}
	
	/**
	 * Gets the PlayerStatistics.class instance.
	 * @return the PlayerStatistics.class instance.
	 */
	public PlayerStatistics getStats() {
		return stats;
	}
	
	/**
	 * Sets all the data in PlayerStatistics to their original values.
	 */
	public void setDefaults() {
		getStats().level = 0;
		getStats().EP = 20;
		getStats().HP = 20;
		getStats().MAX_HP=20;
		getStats().MAX_EP=20;
		getStats().experience=0;
		
	}
	
	public boolean useMagic(int cost ) {
		if(getStats().EP-cost>=0){
			getStats().EP-=cost;
			return true;
			}
		return false;
		
	}
	public void experienceUP(int experience){
		getStats().experience+=experience;
		int prelevel=getStats().level;
		getStats().level=getStats().experience/20;
		if(prelevel!=getStats().level){
			getStats().MAX_EP+=20;
			getStats().EP=getStats().MAX_EP;
			
			
			
		}
		
	}

	public void respawn() {
		getStats().EP=getStats().MAX_EP;
		getStats().HP=getStats().MAX_HP;
	}
	public void playerHurt(int hurt) {
		getStats().HP-=hurt;
		
	
		
	}
	public void dead() {
		if(getStats().level>0){
		if(getStats().experience -getStats().level*20>=0)
			getStats().experience -=20;
		getStats().level=getStats().experience/20;
		getStats().MAX_EP-=20;
		getStats().MAX_HP-=20;

		}
		
	}

	
	
}
